package tests;

import com.baomidou.lock.annotation.Lock4j;
import com.baomidou.lock.executor.RedissonLockExecutor;
import org.springframework.stereotype.Service;

@Service
public class EasyService {

    //默认获取锁超时3秒，30秒锁过期
    @Lock4j
    public void simple() {
        //do something
    }

    //完全配置，支持spel
    @Lock4j(keys = {"#user.id", "#user.name"}, expire = 60000, acquireTimeout = 1000)
    public User customMethod(User user) {
        return user;
    }

    //可在方法级指定使用某种执行器，若自己实现的需要提前注入到Spring。
    @Lock4j(executor = RedissonLockExecutor.class)
    public Boolean test() {
        return Boolean.TRUE;
    }

    // 指定时间内不释放锁(限流)
    // 用户在5秒内只能访问1次
    @Lock4j(keys = {"#user.id"}, acquireTimeout = 0, expire = 5000, autoRelease = false)
    public Boolean test(User user) {
        return Boolean.TRUE;
    }

}